package cn.edu.cqut.test1;

import java.io.Serializable;

import cn.edu.cqut.test0409.Birthday;

public class Person implements Comparable<Person>, Cloneable, Serializable {
	public static void main(String[] args) {
		Person per = new Person();
	}

	public Person() {
//		this.name = "张三";
//		this.age = 0;
//		total++;
		this("张三", 0);
//		System.out.println("Persons::Person()");
	}

	public Person(String name, int age) {
//		System.out.println("Persons::Person(String name, int age)");
		this.name = name;
		this.age = age;
		age = 20;
		int a;
		total++;
	}

	// 数据域
	// 静态属性(成员变量)
	private String name;
	private int age;
	private static int total = 0;
	transient public Birthday bir;

	// 访问器
	public String getName() {
		return this.name;
	}

	// 修改器
	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public void showInfo() {
		System.out.println("姓名：" + getName() + ", 年龄：" + getAge());
	}

	// 方法域
	// 动态属性(成员方法)
	public void sayHello() {
		showTotal();
		System.out.println(this.name + "说，你好，我已经" + this.age + "岁了。");
	}

	public static void showTotal() {
		System.out.println("总人口数：" + total);
	}

	@Override
	public String toString() {
		if(bir==null)
			return "姓名：" + name + ", 年龄：" + age + ", 出生年份："+ "\n";
		else
			return "姓名：" + name + ", 年龄：" + age + ", 出生年份：" + bir.year + "\n";
	}

	@Override
	public int compareTo(Person o) {
		return this.name.compareTo(o.name);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj instanceof Person) {
			Person per = (Person) obj;
			return this.name.equals(per.name);
		}
		return false;
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		Person per = (Person)super.clone();
		per.bir = (Birthday)this.bir.clone();
		return per;
	}
}
